#encoding=utf-8
from django.http import HttpResponse
from django.shortcuts import render_to_response
from tool import temp_map as map
from tool.service import serviceMap
import json
import MySQLdb
from config.settings import DATABASES

cfg={
   'root':'yqy',
   'pageTitle':'首页',
   'my_config':{
            'debug':True
        }
   }
#特殊服务配置 
actionMap={
    
}
#默认路径
defActionModule="actionModule"                    
def root(self): 
    #return render_to_response(map["config"], cfg) 
    return render_to_response(map["index"], cfg) 

def action(request): 
    do=request.GET.get("action")
    handleName=None
    index=do.find(".")
    if index>-1:
        handleName=do[0:index]
        do=do[index+1:len(do)]
    
    module=None;
    if handleName and serviceMap.has_key(handleName):
        module=serviceMap[handleName]
    else:
        module=serviceMap['_base_']
    serv=module.get('serv')()
    #解析参数
    serv.initParam(request,module.get('param'),handleName)
    #执行函数
    result=getattr(serv,do)()
    if isinstance(result, HttpResponse):
        return result
    elif isinstance(result, basestring):
        return HttpResponse(result);
    else:
        #是否封装对结果处理
        return HttpResponse(json.dumps(result));
    
    